﻿using System;
using System.Collections.Generic;

namespace PowerPatcherInterop
{
	/// <summary>
	/// Description of MyClass.
	/// </summary>
	public interface iPlugIn
	{
        /// <summary>
        /// The name of the add in
        /// </summary>
        string Name { get; }
        
        /// <summary>
        /// Called immediatly after loading a plugin. Treat it as a "void Main()" or "OnStartup()". Any AssemblyResolve (to resolve dependancies) should be added here.
        /// </summary>
        /// <param name="info">A class containing startup information from the Patcher</param>
		void Initialize(InitInfo info);
		
		/// <summary>
		/// The patcher calls this method when the "Patch Now!" button is pressed. The plugin should run its main function (eg Patching the Client) when this method is called. If your plugin doesn't fit this catagory, simply create an empty method body.
		/// </summary>    
        void RunPlugin();
        
        /// <summary>
        /// This is where you should return a new instance of your UI class.
        /// </summary>
        /// <returns>A usercontrol which is placed on the plugin's Tab Page</returns>
        System.Windows.Controls.UserControl GetAddInUI();
   
        /// <summary>
        /// The patcher uses this to identify the tab page. It should be stored in a local variable, created in the Initialize() method.
        /// </summary>
        /// <returns>A GUID which the Patcher uses to identify the plugin.</returns>
        Guid GetGUID();
	}
    public class InitInfo
    {
        /// <summary>
        /// Invoke this delegate to write a string to the log. If the bool is "True", an error message box is displayed to the user containing the string.
        /// </summary>
        public Action<string, bool> LogString;

        /// <summary>
        /// Invoke this delegate to log an exception. The verboseness depends on the user's setting. The bool determines of an eror message box is displayed as well.
        /// </summary>
        public Action<Exception, bool> LogException;
        
        /// <summary>
        /// Invoke this delegate to change the display of the "main" (blue) progress area. Double is the value of the bar, from 0-1. Passing a negative value keeps the current value of the bar. String is the text to display to the bar's left. Passing null keeps the current text.
        /// </summary>
        public Action<double, string> MainUpdater;
        
        /// <summary>
        /// A collection of delegates that update the "sub" (green) progress displays. Array numbering starts at 0, 0 being the area closest to the Main progress area. Uses the same format as the Main Progress Updater.
        /// </summary>
        public Action<double, string>[] SupUpdaters;
        
        /// <summary>
        /// Sets the main patch flag. This disables all buttons without "NoDisable" in the tag. Make SURE to call this with False when you're done!
        /// </summary>
        public Action<bool> SetPatchState;
        
        /// <summary>
        /// Gets the state of the main patch flag.
        /// </summary>
        public Func<bool> GetPatchState;
        
        /// <summary>
        /// Gets the setting "show detailed errors". Based on this esult, you should return ex.Message or ex.ToString()
        /// </summary>
        /// <returns></returns>
        public Func<bool> GetShowDetailedError;
        
        /// <summary>
        /// A string containg the path to the DLL that the current class was loaded from.
        /// </summary>
        public string AddInLocation;
    }
}